use std::time::Duration;
use lightspeed_scheduler::{job::Job, scheduler::{Scheduler, TryToScheduler}, JobExecutor};

#[tokio::main]
async fn main() {
    let executor = JobExecutor::new_with_utc_tz();

    // Run every 10 seconds with no retries in case of failure
    let retries = None;
    executor
        .add_job_with_scheduler(
            Scheduler::Interval {
                interval_duration: Duration::from_secs(10),
                execute_at_startup: true,
            },
            Job::new("hello_job", "job_1", retries, move || {
                Box::pin(async move {
                    println!("Hello from job. This happens every 10 seconds!");
                    Ok(())
                })
            }),
        )
        .await;


    // Run every day at 2:00 am with two retries in case of failure
    let retries = Some(2);
    executor
    .add_job_with_scheduler(
        "0 0 2 * * *".to_scheduler().unwrap(),
        Job::new("hello_job", "job_2", retries, move || {
            Box::pin(async move {
                println!("Hello from job. This happens every day at 2 am!");
                Ok(())
            })
        }),
    )
    .await;

    // Start the job executor
    let _executor_handle = executor.run().await.expect("The job executor should run!");

    // Wait for a signal to stop the job executor
    tokio::signal::ctrl_c().await.unwrap();
    
    // Stop the job executor
    let stop_gracefully = true;
    executor.stop(stop_gracefully).await.expect("The job executor should stop!");
}